{
 "cells": [
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "# Copyright 2025 Apache Software Foundation\n",
    "#\n",
    "# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
    "# you may not use this file except in compliance with the License.\n",
    "# You may obtain a copy of the License at\n",
    "#\n",
    "#     http://www.apache.org/licenses/LICENSE-2.0\n",
    "#\n",
    "# Unless required by applicable law or agreed to in writing, software\n",
    "# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
    "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
    "# See the License for the specific language governing permissions and\n",
    "# limitations under the License."
   ],
   "id": "4d47e95ddd66c645"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: burr[start] in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (0.39.1)\n",
      "Requirement already satisfied: streamlit in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (1.44.1)\n",
      "Requirement already satisfied: graphviz in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (0.20.3)\n",
      "Requirement already satisfied: matplotlib in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (3.10.1)\n",
      "Requirement already satisfied: sf-hamilton in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (1.88.0)\n",
      "Requirement already satisfied: loguru in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (0.7.3)\n",
      "Requirement already satisfied: click in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (8.1.8)\n",
      "Requirement already satisfied: requests in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (2.32.3)\n",
      "Requirement already satisfied: opentelemetry-api in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (1.32.1)\n",
      "Requirement already satisfied: opentelemetry-sdk in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (1.32.1)\n",
      "Requirement already satisfied: opentelemetry-instrumentation-openai in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (0.39.2)\n",
      "Requirement already satisfied: pydantic>1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (2.11.3)\n",
      "Requirement already satisfied: fastapi in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (0.115.12)\n",
      "Requirement already satisfied: uvicorn in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (0.34.1)\n",
      "Requirement already satisfied: pydantic-settings in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (2.9.1)\n",
      "Requirement already satisfied: fastapi-pagination in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (0.12.34)\n",
      "Requirement already satisfied: fastapi-utils in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (0.8.0)\n",
      "Requirement already satisfied: aiofiles in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (24.1.0)\n",
      "Requirement already satisfied: jinja2 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (3.1.6)\n",
      "Requirement already satisfied: openai in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (1.75.0)\n",
      "Requirement already satisfied: typing-inspect in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from burr[start]) (0.9.0)\n",
      "Requirement already satisfied: contourpy>=1.0.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from matplotlib->burr[start]) (1.3.2)\n",
      "Requirement already satisfied: cycler>=0.10 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from matplotlib->burr[start]) (0.12.1)\n",
      "Requirement already satisfied: fonttools>=4.22.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from matplotlib->burr[start]) (4.57.0)\n",
      "Requirement already satisfied: kiwisolver>=1.3.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from matplotlib->burr[start]) (1.4.8)\n",
      "Requirement already satisfied: numpy>=1.23 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from matplotlib->burr[start]) (2.2.4)\n",
      "Requirement already satisfied: packaging>=20.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from matplotlib->burr[start]) (24.2)\n",
      "Requirement already satisfied: pillow>=8 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from matplotlib->burr[start]) (11.2.1)\n",
      "Requirement already satisfied: pyparsing>=2.3.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from matplotlib->burr[start]) (3.2.3)\n",
      "Requirement already satisfied: python-dateutil>=2.7 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from matplotlib->burr[start]) (2.9.0.post0)\n",
      "Requirement already satisfied: deprecated>=1.2.6 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from opentelemetry-api->burr[start]) (1.2.18)\n",
      "Requirement already satisfied: importlib-metadata<8.7.0,>=6.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from opentelemetry-api->burr[start]) (8.6.1)\n",
      "Requirement already satisfied: opentelemetry-instrumentation>=0.50b0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from opentelemetry-instrumentation-openai->burr[start]) (0.53b1)\n",
      "Requirement already satisfied: opentelemetry-semantic-conventions>=0.50b0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from opentelemetry-instrumentation-openai->burr[start]) (0.53b1)\n",
      "Requirement already satisfied: opentelemetry-semantic-conventions-ai==0.4.3 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from opentelemetry-instrumentation-openai->burr[start]) (0.4.3)\n",
      "Requirement already satisfied: tiktoken<1,>=0.6.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from opentelemetry-instrumentation-openai->burr[start]) (0.9.0)\n",
      "Requirement already satisfied: typing-extensions>=3.7.4 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from opentelemetry-sdk->burr[start]) (4.13.2)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from requests->burr[start]) (3.4.1)\n",
      "Requirement already satisfied: idna<4,>=2.5 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from requests->burr[start]) (3.10)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from requests->burr[start]) (2.4.0)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from requests->burr[start]) (2025.1.31)\n",
      "Requirement already satisfied: pandas in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from sf-hamilton->burr[start]) (2.2.3)\n",
      "Requirement already satisfied: altair<6,>=4.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from streamlit->burr[start]) (5.5.0)\n",
      "Requirement already satisfied: blinker<2,>=1.0.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from streamlit->burr[start]) (1.9.0)\n",
      "Requirement already satisfied: cachetools<6,>=4.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from streamlit->burr[start]) (5.5.2)\n",
      "Requirement already satisfied: protobuf<6,>=3.20 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from streamlit->burr[start]) (5.29.4)\n",
      "Requirement already satisfied: pyarrow>=7.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from streamlit->burr[start]) (19.0.1)\n",
      "Requirement already satisfied: tenacity<10,>=8.1.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from streamlit->burr[start]) (9.1.2)\n",
      "Requirement already satisfied: toml<2,>=0.10.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from streamlit->burr[start]) (0.10.2)\n",
      "Requirement already satisfied: watchdog<7,>=2.1.5 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from streamlit->burr[start]) (6.0.0)\n",
      "Requirement already satisfied: gitpython!=3.1.19,<4,>=3.0.7 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from streamlit->burr[start]) (3.1.44)\n",
      "Requirement already satisfied: pydeck<1,>=0.8.0b4 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from streamlit->burr[start]) (0.9.1)\n",
      "Requirement already satisfied: tornado<7,>=6.0.3 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from streamlit->burr[start]) (6.4.2)\n",
      "Requirement already satisfied: jsonschema>=3.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from altair<6,>=4.0->streamlit->burr[start]) (4.23.0)\n",
      "Requirement already satisfied: narwhals>=1.14.2 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from altair<6,>=4.0->streamlit->burr[start]) (1.35.0)\n",
      "Requirement already satisfied: wrapt<2,>=1.10 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from deprecated>=1.2.6->opentelemetry-api->burr[start]) (1.17.2)\n",
      "Requirement already satisfied: gitdb<5,>=4.0.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from gitpython!=3.1.19,<4,>=3.0.7->streamlit->burr[start]) (4.0.12)\n",
      "Requirement already satisfied: zipp>=3.20 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from importlib-metadata<8.7.0,>=6.0->opentelemetry-api->burr[start]) (3.21.0)\n",
      "Requirement already satisfied: pytz>=2020.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from pandas->sf-hamilton->burr[start]) (2025.2)\n",
      "Requirement already satisfied: tzdata>=2022.7 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from pandas->sf-hamilton->burr[start]) (2025.2)\n",
      "Requirement already satisfied: annotated-types>=0.6.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from pydantic>1->burr[start]) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.33.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from pydantic>1->burr[start]) (2.33.1)\n",
      "Requirement already satisfied: typing-inspection>=0.4.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from pydantic>1->burr[start]) (0.4.0)\n",
      "Requirement already satisfied: MarkupSafe>=2.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from jinja2->burr[start]) (3.0.2)\n",
      "Requirement already satisfied: six>=1.5 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from python-dateutil>=2.7->matplotlib->burr[start]) (1.17.0)\n",
      "Requirement already satisfied: regex>=2022.1.18 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from tiktoken<1,>=0.6.0->opentelemetry-instrumentation-openai->burr[start]) (2024.11.6)\n",
      "Requirement already satisfied: starlette<0.47.0,>=0.40.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from fastapi->burr[start]) (0.46.2)\n",
      "Requirement already satisfied: psutil<6,>=5 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from fastapi-utils->burr[start]) (5.9.8)\n",
      "Requirement already satisfied: anyio<5,>=3.5.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai->burr[start]) (4.9.0)\n",
      "Requirement already satisfied: distro<2,>=1.7.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai->burr[start]) (1.9.0)\n",
      "Requirement already satisfied: httpx<1,>=0.23.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai->burr[start]) (0.28.1)\n",
      "Requirement already satisfied: jiter<1,>=0.4.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai->burr[start]) (0.9.0)\n",
      "Requirement already satisfied: sniffio in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai->burr[start]) (1.3.1)\n",
      "Requirement already satisfied: tqdm>4 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai->burr[start]) (4.67.1)\n",
      "Requirement already satisfied: python-dotenv>=0.21.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from pydantic-settings->burr[start]) (1.1.0)\n",
      "Requirement already satisfied: mypy-extensions>=0.3.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from typing-inspect->burr[start]) (1.0.0)\n",
      "Requirement already satisfied: h11>=0.8 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from uvicorn->burr[start]) (0.14.0)\n",
      "Requirement already satisfied: smmap<6,>=3.0.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from gitdb<5,>=4.0.1->gitpython!=3.1.19,<4,>=3.0.7->streamlit->burr[start]) (5.0.2)\n",
      "Requirement already satisfied: httpcore==1.* in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from httpx<1,>=0.23.0->openai->burr[start]) (1.0.8)\n",
      "Requirement already satisfied: attrs>=22.2.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit->burr[start]) (25.3.0)\n",
      "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit->burr[start]) (2024.10.1)\n",
      "Requirement already satisfied: referencing>=0.28.4 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit->burr[start]) (0.36.2)\n",
      "Requirement already satisfied: rpds-py>=0.7.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from jsonschema>=3.0->altair<6,>=4.0->streamlit->burr[start]) (0.24.0)\n",
      "\n",
      "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m24.3.1\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m25.1\u001B[0m\n",
      "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpip install --upgrade pip\u001B[0m\n",
      "Requirement already satisfied: openai in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (1.75.0)\n",
      "Requirement already satisfied: anyio<5,>=3.5.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai) (4.9.0)\n",
      "Requirement already satisfied: distro<2,>=1.7.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai) (1.9.0)\n",
      "Requirement already satisfied: httpx<1,>=0.23.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai) (0.28.1)\n",
      "Requirement already satisfied: jiter<1,>=0.4.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai) (0.9.0)\n",
      "Requirement already satisfied: pydantic<3,>=1.9.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai) (2.11.3)\n",
      "Requirement already satisfied: sniffio in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai) (1.3.1)\n",
      "Requirement already satisfied: tqdm>4 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai) (4.67.1)\n",
      "Requirement already satisfied: typing-extensions<5,>=4.11 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from openai) (4.13.2)\n",
      "Requirement already satisfied: idna>=2.8 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from anyio<5,>=3.5.0->openai) (3.10)\n",
      "Requirement already satisfied: certifi in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from httpx<1,>=0.23.0->openai) (2025.1.31)\n",
      "Requirement already satisfied: httpcore==1.* in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from httpx<1,>=0.23.0->openai) (1.0.8)\n",
      "Requirement already satisfied: h11<0.15,>=0.13 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from httpcore==1.*->httpx<1,>=0.23.0->openai) (0.14.0)\n",
      "Requirement already satisfied: annotated-types>=0.6.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from pydantic<3,>=1.9.0->openai) (0.7.0)\n",
      "Requirement already satisfied: pydantic-core==2.33.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from pydantic<3,>=1.9.0->openai) (2.33.1)\n",
      "Requirement already satisfied: typing-inspection>=0.4.0 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from pydantic<3,>=1.9.0->openai) (0.4.0)\n",
      "\n",
      "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m24.3.1\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m25.1\u001B[0m\n",
      "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpip install --upgrade pip\u001B[0m\n",
      "Requirement already satisfied: tavily-python in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (0.5.4)\n",
      "Requirement already satisfied: requests in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from tavily-python) (2.32.3)\n",
      "Requirement already satisfied: tiktoken>=0.5.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from tavily-python) (0.9.0)\n",
      "Requirement already satisfied: httpx in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from tavily-python) (0.28.1)\n",
      "Requirement already satisfied: regex>=2022.1.18 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from tiktoken>=0.5.1->tavily-python) (2024.11.6)\n",
      "Requirement already satisfied: charset-normalizer<4,>=2 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from requests->tavily-python) (3.4.1)\n",
      "Requirement already satisfied: idna<4,>=2.5 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from requests->tavily-python) (3.10)\n",
      "Requirement already satisfied: urllib3<3,>=1.21.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from requests->tavily-python) (2.4.0)\n",
      "Requirement already satisfied: certifi>=2017.4.17 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from requests->tavily-python) (2025.1.31)\n",
      "Requirement already satisfied: anyio in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from httpx->tavily-python) (4.9.0)\n",
      "Requirement already satisfied: httpcore==1.* in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from httpx->tavily-python) (1.0.8)\n",
      "Requirement already satisfied: h11<0.15,>=0.13 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from httpcore==1.*->httpx->tavily-python) (0.14.0)\n",
      "Requirement already satisfied: sniffio>=1.1 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from anyio->httpx->tavily-python) (1.3.1)\n",
      "Requirement already satisfied: typing_extensions>=4.5 in /home/maggie/.pyenv/versions/3.12.9/lib/python3.12/site-packages (from anyio->httpx->tavily-python) (4.13.2)\n",
      "\n",
      "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m A new release of pip is available: \u001B[0m\u001B[31;49m24.3.1\u001B[0m\u001B[39;49m -> \u001B[0m\u001B[32;49m25.1\u001B[0m\n",
      "\u001B[1m[\u001B[0m\u001B[34;49mnotice\u001B[0m\u001B[1;39;49m]\u001B[0m\u001B[39;49m To update, run: \u001B[0m\u001B[32;49mpip install --upgrade pip\u001B[0m\n"
     ]
    }
   ],
   "execution_count": 1,
   "source": [
    "!pip install burr[start]\n",
    "!pip install openai\n",
    "!pip install tavily-python"
   ],
   "id": "e88d57bd5e8cffb"
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "ed859b06-bcd5-4a6b-abcd-ab5863e17b37",
   "metadata": {},
   "outputs": [],
   "source": [
    "from application import application as researcher_app"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "84d778f6-79e6-4a97-9360-48745f918c78",
   "metadata": {},
   "source": [
    "## Deep Researcher\n",
    "\n",
    "This is an example of a research assistant agent that uses llm chat and llm-friendly search together to provide a report, complete with internet citations, on a topic of the user's choosing. The graph for the agent includes optional reflection and re-writing that is implemented as a loop. This particular version of a research assistant uses the OpenAI API code for chat and the Tavily API for search. \n",
    "\n",
    "Given a research topic, the research assistant flow consists of several steps. On initialization, the assistant must:\n",
    "\n",
    "1. Use the chat API to generate a search query for web search based on the research topic.\n",
    "\n",
    "It then loops through the following three steps as many times as the user desires, controlled by the variable `num_loops`.\n",
    "\n",
    "2. Perform web research based on the search query using the search API.\n",
    "3. Use the chat API to summarize the web research gathered in the previous step.\n",
    "4. Reflect on the summary to generate a follow-up search query.\n",
    "\n",
    "When the number of loops is exhausted, the assistant must:\n",
    "\n",
    "5. Finalize summary with formatted sources and return it to the user.\n",
    "\n",
    "The graph for the application is visualized below.\n",
    "   \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "c8d7c2c9-7f05-4447-b084-88bdd73e75f9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/svg+xml": [
       "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n",
       "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"\n",
       " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n",
       "<!-- Generated by graphviz version 2.43.0 (0)\n",
       " -->\n",
       "<!-- Title: %3 Pages: 1 -->\n",
       "<svg width=\"399pt\" height=\"399pt\"\n",
       " viewBox=\"0.00 0.00 399.22 399.00\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\">\n",
       "<g id=\"graph0\" class=\"graph\" transform=\"scale(1 1) rotate(0) translate(4 395)\">\n",
       "<title>%3</title>\n",
       "<polygon fill=\"white\" stroke=\"transparent\" points=\"-4,4 -4,-395 395.22,-395 395.22,4 -4,4\"/>\n",
       "<!-- generate_query -->\n",
       "<g id=\"node1\" class=\"node\">\n",
       "<title>generate_query</title>\n",
       "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M347,-323C347,-323 239,-323 239,-323 233,-323 227,-317 227,-311 227,-311 227,-298 227,-298 227,-292 233,-286 239,-286 239,-286 347,-286 347,-286 353,-286 359,-292 359,-298 359,-298 359,-311 359,-311 359,-317 353,-323 347,-323\"/>\n",
       "<text text-anchor=\"middle\" x=\"293\" y=\"-300.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">generate_query</text>\n",
       "</g>\n",
       "<!-- web_research -->\n",
       "<g id=\"node3\" class=\"node\">\n",
       "<title>web_research</title>\n",
       "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M242.5,-255C242.5,-255 149.5,-255 149.5,-255 143.5,-255 137.5,-249 137.5,-243 137.5,-243 137.5,-230 137.5,-230 137.5,-224 143.5,-218 149.5,-218 149.5,-218 242.5,-218 242.5,-218 248.5,-218 254.5,-224 254.5,-230 254.5,-230 254.5,-243 254.5,-243 254.5,-249 248.5,-255 242.5,-255\"/>\n",
       "<text text-anchor=\"middle\" x=\"196\" y=\"-232.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">web_research</text>\n",
       "</g>\n",
       "<!-- generate_query&#45;&gt;web_research -->\n",
       "<g id=\"edge2\" class=\"edge\">\n",
       "<title>generate_query&#45;&gt;web_research</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M267.26,-285.99C255.97,-278.3 242.55,-269.17 230.42,-260.92\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"232.1,-257.83 221.86,-255.1 228.16,-263.61 232.1,-257.83\"/>\n",
       "</g>\n",
       "<!-- input__research_topic -->\n",
       "<g id=\"node2\" class=\"node\">\n",
       "<title>input__research_topic</title>\n",
       "<polygon fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" points=\"376.5,-391 209.5,-391 209.5,-354 376.5,-354 376.5,-391\"/>\n",
       "<text text-anchor=\"middle\" x=\"293\" y=\"-368.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">input: research_topic</text>\n",
       "</g>\n",
       "<!-- input__research_topic&#45;&gt;generate_query -->\n",
       "<g id=\"edge1\" class=\"edge\">\n",
       "<title>input__research_topic&#45;&gt;generate_query</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M293,-353.81C293,-347.6 293,-340.45 293,-333.6\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"296.5,-333.24 293,-323.24 289.5,-333.24 296.5,-333.24\"/>\n",
       "</g>\n",
       "<!-- summarize_sources -->\n",
       "<g id=\"node4\" class=\"node\">\n",
       "<title>summarize_sources</title>\n",
       "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M148,-187C148,-187 12,-187 12,-187 6,-187 0,-181 0,-175 0,-175 0,-162 0,-162 0,-156 6,-150 12,-150 12,-150 148,-150 148,-150 154,-150 160,-156 160,-162 160,-162 160,-175 160,-175 160,-181 154,-187 148,-187\"/>\n",
       "<text text-anchor=\"middle\" x=\"80\" y=\"-164.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">summarize_sources</text>\n",
       "</g>\n",
       "<!-- web_research&#45;&gt;summarize_sources -->\n",
       "<g id=\"edge3\" class=\"edge\">\n",
       "<title>web_research&#45;&gt;summarize_sources</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M165.22,-217.99C151.32,-210.08 134.73,-200.64 119.9,-192.2\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"121.35,-189 110.93,-187.1 117.89,-195.08 121.35,-189\"/>\n",
       "</g>\n",
       "<!-- reflect_on_summary -->\n",
       "<g id=\"node5\" class=\"node\">\n",
       "<title>reflect_on_summary</title>\n",
       "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M265.5,-119C265.5,-119 126.5,-119 126.5,-119 120.5,-119 114.5,-113 114.5,-107 114.5,-107 114.5,-94 114.5,-94 114.5,-88 120.5,-82 126.5,-82 126.5,-82 265.5,-82 265.5,-82 271.5,-82 277.5,-88 277.5,-94 277.5,-94 277.5,-107 277.5,-107 277.5,-113 271.5,-119 265.5,-119\"/>\n",
       "<text text-anchor=\"middle\" x=\"196\" y=\"-96.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">reflect_on_summary</text>\n",
       "</g>\n",
       "<!-- summarize_sources&#45;&gt;reflect_on_summary -->\n",
       "<g id=\"edge4\" class=\"edge\">\n",
       "<title>summarize_sources&#45;&gt;reflect_on_summary</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M110.78,-149.99C124.68,-142.08 141.27,-132.64 156.1,-124.2\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"158.11,-127.08 165.07,-119.1 154.65,-121 158.11,-127.08\"/>\n",
       "</g>\n",
       "<!-- reflect_on_summary&#45;&gt;web_research -->\n",
       "<g id=\"edge6\" class=\"edge\">\n",
       "<title>reflect_on_summary&#45;&gt;web_research</title>\n",
       "<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M196,-119.02C196,-141.6 196,-181.1 196,-207.77\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"192.5,-207.98 196,-217.98 199.5,-207.98 192.5,-207.98\"/>\n",
       "<text text-anchor=\"middle\" x=\"279.5\" y=\"-164.8\" font-family=\"Times,serif\" font-size=\"14.00\">research_loop_count&lt;2</text>\n",
       "</g>\n",
       "<!-- finalize_summary -->\n",
       "<g id=\"node6\" class=\"node\">\n",
       "<title>finalize_summary</title>\n",
       "<path fill=\"#b4d8e4\" stroke=\"black\" d=\"M354.5,-37C354.5,-37 233.5,-37 233.5,-37 227.5,-37 221.5,-31 221.5,-25 221.5,-25 221.5,-12 221.5,-12 221.5,-6 227.5,0 233.5,0 233.5,0 354.5,0 354.5,0 360.5,0 366.5,-6 366.5,-12 366.5,-12 366.5,-25 366.5,-25 366.5,-31 360.5,-37 354.5,-37\"/>\n",
       "<text text-anchor=\"middle\" x=\"294\" y=\"-14.8\" font-family=\"Helvetica,sans-Serif\" font-size=\"14.00\">finalize_summary</text>\n",
       "</g>\n",
       "<!-- reflect_on_summary&#45;&gt;finalize_summary -->\n",
       "<g id=\"edge5\" class=\"edge\">\n",
       "<title>reflect_on_summary&#45;&gt;finalize_summary</title>\n",
       "<path fill=\"none\" stroke=\"black\" stroke-dasharray=\"5,2\" d=\"M197.41,-81.82C199.05,-71.97 202.55,-60.1 210,-52 213.27,-48.45 216.97,-45.28 220.96,-42.46\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"222.86,-45.4 229.48,-37.13 219.15,-39.46 222.86,-45.4\"/>\n",
       "<text text-anchor=\"middle\" x=\"293.5\" y=\"-55.8\" font-family=\"Times,serif\" font-size=\"14.00\">research_loop_count=2</text>\n",
       "</g>\n",
       "<!-- finalize_summary&#45;&gt;generate_query -->\n",
       "<g id=\"edge7\" class=\"edge\">\n",
       "<title>finalize_summary&#45;&gt;generate_query</title>\n",
       "<path fill=\"none\" stroke=\"black\" d=\"M357.76,-37.22C364.91,-41.21 371.56,-46.07 377,-52 391.87,-68.22 391,-77.49 391,-99.5 391,-237.5 391,-237.5 391,-237.5 391,-256.89 377.64,-270.96 360.78,-280.99\"/>\n",
       "<polygon fill=\"black\" stroke=\"black\" points=\"358.85,-278.06 351.7,-285.88 362.17,-284.22 358.85,-278.06\"/>\n",
       "</g>\n",
       "</g>\n",
       "</svg>\n"
      ],
      "text/plain": [
       "<graphviz.graphs.Digraph at 0x7eaec88f7a70>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "app = researcher_app(app_id=\"1\")\n",
    "app.visualize(include_conditions=True)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1601d582-1a0b-435e-8f92-ffc7a44d4ca4",
   "metadata": {},
   "source": [
    "To run the application, we need tokens for the OpenAI api and the Tavily api."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a899bf02-7f54-4cf2-ad80-bf37b62f07e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "os.environ[\"OPENAI_API_KEY\"] = \"sk-*\"\n",
    "os.environ[\"TAVILY_API_KEY\"] = \"tvly-*\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "4e18b2ad-4696-4c15-84b6-04c3ba515d30",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Warning: No raw_content found for source https://www.linkedin.com/pulse/how-crack-data-science-interview-2023-khadar-valli\n",
      "Warning: No raw_content found for source https://dataspace.com/data-job-seekers/2023-top-data-science-skills/\n",
      "## Summary\n",
      "\n",
      "To secure a job in data science, it's crucial to prepare effectively for interviews by thoroughly researching the company and understanding its culture, aligning your skills with its business objectives. Tailoring your preparation to the specific interview process of each company can significantly enhance your chances of success.\n",
      "\n",
      "In 2023, certain skills are particularly in demand. Python stands out as the most sought-after skill due to its versatile applications in automation, machine learning, and system building. Its extensive library support and easy-to-read syntax make it popular in the data science field. Acquiring proficiency in Python can be a strong asset for aspiring data scientists and can significantly increase job prospects in the field.\n",
      "\n",
      " ### Sources:\n",
      "* HOW TO CRACK DATA SCIENCE INTERVIEW IN 2023 - LinkedIn : https://www.linkedin.com/pulse/how-crack-data-science-interview-2023-khadar-valli\n",
      "* Top 10 Data Science Skills for 2023 - Dataspace : https://dataspace.com/data-job-seekers/2023-top-data-science-skills/\n"
     ]
    }
   ],
   "source": [
    "my_research_topic = \"getting a job in datascience\"\n",
    "action, state, result = app.run(halt_after=[\"finalize_summary\"], inputs={\"research_topic\": my_research_topic})\n",
    "print(app.state[\"running_summary\"])     "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf6eed5c-39f1-430c-9eb6-4a5809299fe9",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Warning: No raw_content found for source https://www.foodnetwork.com/how-to/packages/food-network-essentials/beginners-guide-to-canning\n"
     ]
    }
   ],
   "source": [
    "my_research_topic = \"how to get started with canning food at home\"\n",
    "action, state, result = app.run(halt_after=[\"finalize_summary\"], inputs={\"research_topic\": my_research_topic})\n",
    "print(app.state[\"running_summary\"]) "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f716f5d0-f6d3-4bc3-9520-6eaa1a038951",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
